//
//  EJSUpdateUserNickNameViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/1/6.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSUpdateUserNickNameViewController.h"
#import "EJSUpdateUserInfoRequest.h"

@interface EJSUpdateUserNickNameViewController ()
@property (weak, nonatomic) IBOutlet UILimitTextView *nickNameTF;

@end

@implementation EJSUpdateUserNickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"修改姓名";
   
    self.nickNameTF.text = [EJSUserModel userModel].name;
    self.nickNameTF.placeHolder = @"请输入昵称";
    self.nickNameTF.limitLength = 10;
    [self configNavigationRightItmeWithTitle:@"完成" titleColor:AppMainColor font: [UIFont systemFontOfSize:16]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)rightBarButtonAction:(id)sender{
    NSString *nickName = self.nickNameTF.text;
    if(nickName && nickName.length > 0){
        EJSUpdateUserInfoRequest *req = [EJSUpdateUserInfoRequest new];
        req.name = nickName;
        [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
            EJSUserModel *model = [EJSUserModel userModel];
            model.name = nickName;
            [model save];
            [self leftBarButtonAction:nil];
            [[HUDHelper sharedInstance] tipMessage:@"修改成功"];
        } failHandler:^(BaseResponse *response) {
            [[HUDHelper sharedInstance] tipMessage:response.message];
        }];
    }else{
        [[HUDHelper sharedInstance] tipMessage:@"请先输入姓名"];
    }
}



@end
